import {LoanRecord, LoanRecordsGroup} from '../../../model/pages/policy/policy-detail/loan-record';
import {TransferRecord, TransferRecordGroup} from '../../../model/pages/policy/policy-detail/transfer-record';
import {HttpClient, HttpParams} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {Observable} from "rxjs/Observable";
import {PolicyDetail} from '../../../model/pages/policy/policy-detail/policy-detail';
import {UniversalAccount} from '../../../model/pages/policy/policy-detail/universal-account';
import {catchError} from "rxjs/operators";
import {PolicyAcctTrxn} from "../../../model/pages/policy/policy-detail/policy-acct-trxn";

/*
  Generated class for the PolicyDetailProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class PolicyDetailProvider {

    constructor(public http: HttpClient) {
        // console.log('Hello PolicyDetailProvider Provider');
    }

    /**
     * 获取保单详情
     * @param {string} policyId 保单id
     * @returns {Observable<PolicyDetail>}
     */
    getPolicyList(policyId: string, agentCode: string): Observable<PolicyDetail> {
        let params = new HttpParams();
        params = params.set('id', policyId);
        params = params.set('agentCode', agentCode);
        return this.http.get<PolicyDetail>('/policy/v1/policyDetail', {params});
    }

    /**
     * 获取保单银行转账记录
     * @param {string} policyId  保单id
     * @returns {Observable<Array<TransferRecordGroup>>}
     */
    getPolicyAutoPaymentList(policyId: string): Observable<Array<TransferRecordGroup>> {
        let params = new HttpParams();
        params = params.set('id', policyId);
        return this.http.get<Array<TransferRecordGroup>>('/policy/v1/policyAutoPaymentList', {params});
    }

    /**
     * 获取受益人信息
     * @param {string} policyId 保单id
     * @returns {Observable<any>}
     */
    getPolicyBeneficiaryList(policyId: string): Observable<any> {
        let params = new HttpParams();
        params = params.set('policyNum', policyId);
        return this.http.get<any>('/policy/v1/policyBeneficiaryList', {params});
    }

    /**
     * 获取万能账户详情
     * @param {string} policyId 保单id
     * @returns {Observable<Array<UniversalAccount>>}
     */

    getPlicyUniversallList(policyId: string): Observable<Array<UniversalAccount>> {
        let params = new HttpParams();
        params = params.set('policyNum', policyId);
        return this.http.get<Array<UniversalAccount>>('/policy/v1/policyUniversallList', {params});
    }

    /**
     * 获取贷款记录
     * @param {string} policyId 保单id
     * @returns {Observable<Array<LoanRecordsGroup>>}
     */
    getPolicyLoanList(policyId: string): Observable<Array<LoanRecordsGroup>> {
        let params = new HttpParams();
        params = params.set('id', policyId);
        return this.http.get<Array<LoanRecordsGroup>>('/policy/v1/policyLoanList', {params});
    }

    /**
     * 获取投连险详情
     * @param {string} policyId 保单id
     * @returns {Observable<Array<LoanRecordsGroup>>}
     */
    getPolicyAcctTrxnDetail(policyId: string):Observable<PolicyAcctTrxn>{
        let params = new HttpParams();
        params = params.set('policyNum', policyId);
        return this.http.get<PolicyAcctTrxn>('/policy/v1/policyAccTrxnDetail', {params});
    }


}
